/** ***************************************************************************
 * CoffeeTexture.hpp
 * 2012 CoffeeParty Ltd.
 * Date Created: 2012-07-21                                  format YYYY-MM-DD
 * Revision Id: $Id$
 ******************************************************************************
 */

#ifndef _COFFEE_TEXTURE_HPP_
#define _COFFEE_TEXTURE_HPP_

#include "CoffeeCommons.hpp"
#include "CoffeeTypes.hpp"
#include "CoffeeLogger.hpp"
#include "CoffeeRect.hpp"

#include "SugarImage.hpp"

class CoffeeTexture
{
public:
    CoffeeTexture(SugarImage *_image, c_voidp mipmapData = 0);
    CoffeeTexture(SugarImage *_image, c_bool invertRedBlue);
    ~CoffeeTexture();
    c_void createTextureFromImage(c_bool invertRedBlue = false, c_bool hasMipMap = false);
    c_void testDrawOGL(c_dimension<c_int> pixel = c_dimension<c_int>(0, 0), c_int pad = 10);
    c_voidp ark(c_bool readonly = false, c_uint mipmapLevel = 0);
    c_void unark();
    c_dimension<c_uint> getOptimalSize(c_dimension<c_uint>& size, c_bool rulePowerOfTwo = true,
        c_bool ruleSquare = false, c_bool larger = true,
        c_uint maxValue = 0) const;
    c_void getImageValues(SugarImage *_image);
    GLint getParameters(c_uint bits, GLint& filtering, GLenum& colorformat, GLenum& type);
    c_void saveTexture(c_bool newTexture = false, c_voidp _mimapData = 0, c_uint level = 0);
    const c_dimension<c_uint>& getOriginalSize() const;
    const c_dimension<c_uint>& getSize() const;
    GLuint getTextureId() const;
    c_uint getPitch() const;
    c_bool hasMipMaps() const;

protected:
    SugarImage *image;
    SugarImage *mipimage;

    c_dimension<c_uint> imageSize;
    c_dimension<c_uint> textureSize;

    GLuint textureId;
    GLint internalFormat;

    c_ubyte miplevelstored;

    c_bool mipmap;
    c_bool readonlylock;
    c_bool keepData;
};

#endif /** _COFFEE_TEXTURE_HPP_ */
